<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="~{_fragments :: head(~{::title})}">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.5.0/dist/semantic.min.css">
    <link rel="stylesheet" href="../static/css/typo.css">
    <link rel="stylesheet" href="../static/css/animate.css">
    <link rel="stylesheet" href="../static/lib/prism/prism.css">
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
    <link rel="stylesheet" href="../static/css/me.css">
    <style>
        .like-container {
            display: flex !important;
            align-items: center !important;
            justify-content: flex-end !important;
        }
        .like-button {
            cursor: pointer !important;
            color: #888 !important;
            margin-left: 15px !important;
        }
        .like-button.liked {
            color: #ff4500 !important;
        }
        .like-count {
            margin-left: 10px !important;
        }

    </style>
</head>
<body>
<!-- 导航 -->
<nav th:replace="~{_fragments :: menu(1)}"  class="ui inverted attached segment m-padded-tb-mini ">  <!--黑色导航-->
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui Grey header item">Blog</h2>
            <a href="#" class="a-item item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a href="#" class="a-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a href="#" class="a-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a href="#" class="a-item item m-mobile-hide"><i class="clone icon"></i>归档</a>
            <a href="#" class="a-item item m-mobile-hide"><i class="user icon"></i>关于我</a>
            <div class="a-item right item m-mobile-hide">
                <div class="ui icon inverted transparent input">
                    <input type="text" placeholder="搜索">
                    <i class="search link icon"></i>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!-- 主体 -->
<div class="m-padded-tb-big m-container animate__animated animate__fadeIn">
    <div class="ui container">
        <div class="ui top attached segment">
            <div class="ui horizontal link list"><!--发布博客的个人信息-->
                <div class="item">
                    <img src="https://picsum.photos/100/100/?image=1005" th:src="@{${blog.user.avatar}}" alt="" class="ui avatar image">
                    <div class="content"><a href="#" class="header m-opacity-mini"  th:text="${blog.user.nickname}">水果氏</a></div>
                </div>
                <div class="item">
                    <i class="calendar icon"></i><span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2024-09-11</span>
                </div>
                <div class="item">
                    浏览次数：<span th:text="${blog.views}">200</span>
                </div>
            </div>
        </div>
        <div class="ui attached segment">
            <!--图片区域-->
            <img src="https://picsum.photos/800/450/?image=1005" th:src="@{${blog.firstPicture}}" alt="" class="ui fluid rounded image">
        </div>
        <div class="ui  attached padded segment">
            <!--文章-->
            <div class="ui right aligned basic segment">
                <div class="ui orange basic label" th:text="${blog.flag}">原创</div>
            </div>
            <h1 class="ui center aligned header " th:text="${blog.title}">javascript的应用场景和常见用法</h1>
            <br>
            <div id="content" class="typo  typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large" th:utext="${blog.content}">
            </div>
            <!--标签和点赞功能-->
            <div class="m-padded-lr-reponsive">
                <a href="#" th:href="@{/tags/{id}(id=${tag.id})}" class="ui basic blue  label" th:each="tag:${blog.tags}" th:text="${tag.name}">方法论</a>
<!--                <div class="like-container">-->
<!--                    <span id="like-count" class="like-count" th:text="'点赞数：'+${blog.voteCount}">点赞数：0</span>-->
<!--                    &lt;!&ndash; 爱心图案  &ndash;&gt;-->
<!--                    <i id="like-button" class="like ui icon like-button ">-->
<!--                    </i>-->
<!--                </div>-->
            </div>
        </div>
        <div class="ui attached positive message">
        <!-博客信息-->
            <div class="ui middle aligned grid ">
                <div class="eleven wide column ">
                    <ul class="list">
                        <li>作者：<span th:text="${blog.user.nickname}">水果氏</span></li>
                        <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}"></span></li>
                        <li>文章声明：这是一个关于博客的网站，在这里可以看到前端、后端、移动、人工智能等文章，希望你能喜欢。</li>
                        <li>版权声明：本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li>
                        <li>转载请注明出处！</li>
                    </ul>
                </div>
            </div>
        </div>
        <div  class="ui bottom attached segment">
        <!--留言区域列表-->
            <div id="comment-container" class="ui blue segment">
                <div th:fragment="commentList">
                    <div class="ui comments" style="max-width: 100%">
                    <h3 class="ui dividing header">留言区</h3>
                    <div class="comment" th:each="comment:${comments}" >
                        <a class="avatar">
                            <img src="https://picsum.photos/100/100/?image=1005" th:src="@{${comment.avatar}}">
                        </a>
                        <div class="content">
                            <a class="author" th:text="${comment.nickname}">
                                <span>Matt</span>
                                <div class="m-blog-tag " th:if="${comment.adminComment}" >
                                    博主
                                </div>
                            </a>
                            <div class="metadata">
                                <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                            </div>
                            <div class="text" th:text="${comment.content}">
                                How artistic!
                            </div>
                            <div class="actions">
                                <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)" >回复</a>
                            </div>
                        </div>
                        <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
                            <div class="comment" th:each="reply:${comment.replyComments}" >
                                <a class="avatar">
                                    <img src="https://picsum.photos/100/100/?image=1005" th:src="@{${reply.avatar}}">
                                </a>
                                <div class="content">
                                    <a class="author">
                                       <span th:text="${reply.nickname}">小红</span>
                                        <div class="m-blog-tag" th:if="${reply.adminComment}">
                                            博主
                                        </div>
                                       &nbsp;<span th:text="|@ ${reply.parentComment.nickname}|" class="m-blue-text">@ 小白</span>
                                    </a>
                                    <div class="metadata">
                                        <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                    </div>
                                    <div class="text" th:text="${reply.content}">
                                        How artistic!
                                    </div>
                                    <div class="actions">
                                        <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)" >回复</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--/*-->
                    <div class="comment">
                        <a class="avatar">
                            <img src="https://picsum.photos/100/100/?image=1005">
                        </a>
                        <div class="content">
                            <a class="author">Elliot Fu</a>
                            <div class="metadata">
                                <span class="date">Yesterday at 12:30AM</span>
                            </div>
                            <div class="text">
                                <p>This has been very useful for my research. Thanks as well!</p>
                            </div>
                            <div class="actions">
                                <a class="reply">回复</a>
                            </div>
                        </div>
                        <div class="comments">
                            <div class="comment">
                                <a class="avatar">
                                    <img src="https://picsum.photos/100/100/?image=1005">
                                </a>
                                <div class="content">
                                    <a class="author">Jenny Hess</a>
                                    <div class="metadata">
                                        <span class="date">Just now</span>
                                    </div>
                                    <div class="text">
                                        Elliot you are always so right :)
                                    </div>
                                    <div class="actions">
                                        <a class="reply">回复</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="comment">
                        <a class="avatar">
                            <img src="https://picsum.photos/100/100/?image=1005">
                        </a>
                        <div class="content">
                            <a class="author">Joe Henderson</a>
                            <div class="metadata">
                                <span class="date">5 days ago</span>
                            </div>
                            <div class="text">
                                Dude, this is awesome. Thanks so much
                            </div>
                            <div class="actions">
                                <a class="reply">回复</a>
                            </div>
                        </div>
                    </div>
                    <!--*/-->
                </div>
                </div>
            </div>
        <!--留言提交区域-->
            <div id="comment-form" class="ui form">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea name="content" placeholder="请输入留言内容..."></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名" th:value="${session.user}!=null ? ${session.user.nickname}">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                        </div>
                    </div>
                    <div class="field  m-margin-bottom-small m-mobile-wide">  <!--按钮-->
                        <button id="commentpost-btn" type="button" class="ui blue button m-mobile-wide "><i class="edit icon"></i>提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class=" m-fixed m-right-bottom m-padded">
    <div class="ui vertical icon buttons">
        <button  type="button" class="ui toc blue button ">目录</button>
        <a href="#comment-container" class="ui blue button ">留言</a>
        <a href="#" class="ui icon button "><i class="chevron up icon "></i></a>
        <a href="#bottom" class="ui icon button "><i class="chevron down icon"></i></a>
    </div>
</div>

<div class="ui toc-container flowing popup transition hidden" style="width: 250px !important;">
    <ol class="js-toc">
    </ol>
</div>

<!-- 底部 -->
<footer th:block th:replace="_fragments :: footer" id="bottom" class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img src="../static/images/wx.jpg" class="ui rounded image" alt="" style="width: 120px; ">
                        </div>
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced m-text-SimHei">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事 (User Story) </a>
                    <a href="#" class="item">用户故事 (User Story) </a>
                    <a href="#" class="item">用户故事 (User Story) </a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced m-text-SimHei">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">QQ:1541331386 </a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced m-text-SimHei">Fruit_surname</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">这是我的一个博客网址，会分享一下编程，写作，思考，生活之类的相关内容，希望可以给来的这的人一些帮助……</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">copyright ©2023-2026 Fruit_surname Designned by Fruit_surname</p>
    </div>
</footer>
<th:block th:replace="~{_fragments :: script}">
    <!-- 导入 -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script> <!--jQuery-->
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.5.0/dist/semantic.min.js"></script>  <!--semantic-ui框架js-->
    <script src="../static/lib/tocbot/tocbot.min.js"></script>
    <script src="../static/lib/prism/prism.js"></script>
</th:block>
<script>
    $(document).ready(function() {
        let likeCount = 0;
        let liked = false;

        $('#like-button').click(function() {
            liked = !liked;
            likeCount += liked ? 1 : -1;
            $('#like-count').text('点赞数：' + likeCount);
            $(this).toggleClass('liked', liked);
        });
    });
    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    })
    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
        // For headings inside relative or absolute positioned containers within content.
        hasInnerContainers: true,
    });
    //评论表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }
                ]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的大名'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });



    $('#commentpost-btn').click(function () {
        let boo = $('.ui.form').form('validate form');
        if (boo){
            $('#comment-form').submit();
            postData();
        }else {
            alert("请填写必要的信息");
        }
    });
    function postData() {
    var parentCommentId = $("[name='parentComment.id']").val();  // 获取要提交的 parentComment.id
    console.log("Submitting parentComment.id: " + parentCommentId);  // 打印提交的 parentComment.id

    $("#comment-container").load("/comments", {
        "parentComment.id": parentCommentId,  // 提交 parentComment.id
        "blog.id": $("[name='blog.id']").val(),
        "nickname": $("[name='nickname']").val(),
        "email": $("[name='email']").val(),
        "content": $("[name='content']").val()
    }, function(responseTxt, statusTxt, xhr) {
        clearContent();  // 提交成功后清空内容
    });
}




    function clearContent() {
      $("[name='content']").val('');
      $("[name='parentComment.id']").val(-1);
      $("[name='content']").attr("placeholder", "请输入评论信息...");
    }

function reply(obj) {
    var commentId = $(obj).data('commentid');  // 获取回复目标评论的 ID
    var commentNickname = $(obj).data('commentnickname');  // 获取目标评论的昵称

    console.log("Replying to comment ID: " + commentId);  // 打印出回复目标评论的 ID

    // 设置输入框的 placeholder 为目标评论昵称
    $("[name='content']").attr("placeholder", "@" + commentNickname).focus();

    // 设置 parentComment.id 为目标评论的 ID
    $("[name='parentComment.id']").val(commentId);
    console.log("parentComment.id set to: " + $("[name='parentComment.id']").val());  // 确保 parentComment.id 被正确设置

    // 滚动到评论输入框
      $('html, body').animate({
        scrollTop: $('#comment-form').offset().top
    }, 500);
}


 $(function () {
      $("#comment-container").load("[[@{/comments/{id}(id=${blog.id})}]]");
  });

</script>
</body>
</html>
